package com.livepan.business.controller;

import com.livepan.server.BaseController;
import com.livepan.server.error.BusinessException;
import com.livepan.server.response.CommonReturnType;
import com.livepan.server.service.impl.ChapterService;
import com.livepan.server.service.model.ChapterModel;
import com.livepan.server.service.model.ChapterPageModel;
import com.livepan.server.service.model.PageModel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.validation.Validator;


@RestController
@RequestMapping("/chapter")
public class ChapterController extends BaseController {

    public static final String BUSINESS_NAME="大章";

    private static final Logger LOG = LoggerFactory.getLogger(ChapterController.class);

    @Autowired
    private ChapterService chapterService;

    @ResponseBody
    @RequestMapping("/list")
    public CommonReturnType list(ChapterPageModel chapterPageModel) {
        LOG.info("page:" + chapterPageModel.getPage());
        chapterService.list(chapterPageModel);
        return CommonReturnType.create(chapterPageModel);
    }

    @ResponseBody
    @RequestMapping("/save")
    public CommonReturnType chapter(@RequestBody ChapterModel chapterModel) throws BusinessException {
        chapterService.save(chapterModel);
        return CommonReturnType.create(chapterModel);
    }

    @ResponseBody
    @RequestMapping("/delete/{id}")
    public CommonReturnType delete(@PathVariable String id) {
        chapterService.delete(id);
        return CommonReturnType.create(null);
    }
}
